package main

import "fmt"

func main() {
	//注意const中使用iota相当于是行号
	fmt.Println(A1, A2, A3, A4) //0 1 2 3
	fmt.Println(B1, B2, B4)     //0 1 3
	fmt.Println(C1, C2, C3, C4, C5, C6, C8)
	fmt.Println(D1, D2, D3, D4, D5, D6)
	fmt.Println(E1, E2, E3, E5, E6)

	c := RED
	ShowColor(c)
	fmt.Println(G1, G2, G3)
	fmt.Println(KB, MB, GB) //1024...
}

//自增常量 相当于是行号
const (
	A1 = iota //0
	A2        //1
	A3        //2
	A4        //3
)

//可以跳过
const (
	B1 = iota //0
	B2        //1
	_
	B4 //3
)

//中间使用
const (
	C1 = iota //0
	C2 = 10
	C3 = 20
	C4 = iota //3
	C5        //4
	C6        //5
	_
	C8 //7
)

//同一行多个iota
const (
	D1, D2 = iota, iota //0 0
	D3, D4              //1 1
	D5, D6              //2 2
)

const (
	E1, E2 = iota, iota + 1 //0 1
	E3, _                   //1 2
	E5, E6                  //2 3
)

//以下内容编译错误 因为第二行数量不一致
//const (
//	E1, E2 = iota, iota + 1 //0 1
//	E3, E4,E7                  //1 2
//	E5, E6                  //2 3
//)

//定义枚举使用
type Color int

const (
	RED Color = iota
	BLUE
	YELLOW
)

func (c Color) String() string {
	switch c {
	case 0:
		return "RED"
	case 1:
		return "BLUE"
	case 2:
		return "YELLOW"
	default:
		return "未知"
	}
}

func ShowColor(c Color) {
	fmt.Println(c)
}

//结合位操作
const (
	G1 = 1 << iota //1<<0 =1
	G2             //1<<1 等于00000010=2
	G3             //1<<2 等于00000100=4
)

//同样是结合位操作实现大小
type Size float64

const (
	_       = iota
	KB Size = 1 << (10 * iota) // 1 << (10*1)  1024个字节
	MB                         // 1 << (10*2)
	GB                         // 1 << (10*3)
	TB                         // 1 << (10*4)
	PB                         // 1 << (10*5)
	EB                         // 1 << (10*6)
	ZB                         // 1 << (10*7)
	YB                         // 1 << (10*8)
)
